package com.yaorange.teaching.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.yaorange.teaching.bo.HighInterviewMasteryDetailBo;
import com.yaorange.teaching.bo.QueryInterviewMasteryDegreeBo;
import com.yaorange.teaching.bo.RelatedInterviewBo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yaorange.common.log.annotation.Log;
import com.yaorange.common.log.enums.BusinessType;
import com.yaorange.common.security.annotation.RequiresPermissions;
import com.yaorange.teaching.domain.YaHighInterview;
import com.yaorange.teaching.service.IYaHighInterviewService;
import com.yaorange.common.core.web.controller.BaseController;
import com.yaorange.common.core.web.domain.AjaxResult;
import com.yaorange.common.core.utils.poi.ExcelUtil;
import com.yaorange.common.core.web.page.TableDataInfo;

/**
 * 高频面试题Controller
 *
 * @author ruoyi
 * @date 2024-11-15
 */
@RestController
@RequestMapping("/interview")
public class YaHighInterviewController extends BaseController
{
    @Autowired
    private IYaHighInterviewService yaHighInterviewService;



    /**
     * 全量同步到es
     */
    @RequiresPermissions("teaching:interview:list")
    @GetMapping("/export/es")
    public AjaxResult exportEs()
    {
        yaHighInterviewService.exportEs();
        return AjaxResult.success();
    }


    @RequiresPermissions("teaching:interview:list")
    @GetMapping("/export/es/percentage")
    public AjaxResult queryPercentage()
    {
        return AjaxResult.success(yaHighInterviewService.queryPercentage());
    }

    /**
     * 查询高频面试题列表
     */
    @RequiresPermissions("teaching:interview:list")
    @GetMapping("/list/related")
    public AjaxResult queryRelatedInterview(@RequestParam("cdId")Long cdId,@RequestParam("courseContent")String courseContent)
    {
        RelatedInterviewBo result = yaHighInterviewService.selectRelatedInterview(cdId,courseContent);
        return AjaxResult.success(result);
    }
    /**
     * 查询高频面试题列表
     */
    @RequiresPermissions("teaching:interview:list")
    @GetMapping("/list/mastery_degree")
    public TableDataInfo queryMasteryDegreeList(QueryInterviewMasteryDegreeBo queryInterviewMasteryDegreeBo)
    {
        List<HighInterviewMasteryDetailBo> list = yaHighInterviewService.selectHighInterviewMasteryDetailList(queryInterviewMasteryDegreeBo);
        return getDataTable(list);
    }
    /**
     * 查询高频面试题列表
     */
    @RequiresPermissions("teaching:interview:list")
    @GetMapping("/list")
    public TableDataInfo list(YaHighInterview yaHighInterview)
    {
        startPage();
        List<YaHighInterview> list = yaHighInterviewService.selectYaHighInterviewList(yaHighInterview);
        return getDataTable(list);
    }

    /**
     * 导出高频面试题列表
     */
    @RequiresPermissions("teaching:interview:export")
    @Log(title = "高频面试题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YaHighInterview yaHighInterview)
    {
        List<YaHighInterview> list = yaHighInterviewService.selectYaHighInterviewList(yaHighInterview);
        ExcelUtil<YaHighInterview> util = new ExcelUtil<YaHighInterview>(YaHighInterview.class);
        util.exportExcel(response, list, "高频面试题数据");
    }

    /**
     * 获取高频面试题详细信息
     */
    @RequiresPermissions("teaching:interview:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yaHighInterviewService.selectYaHighInterviewById(id));
    }

    /**
     * 新增高频面试题
     */
    @RequiresPermissions("teaching:interview:add")
    @Log(title = "高频面试题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YaHighInterview yaHighInterview)
    {
        return toAjax(yaHighInterviewService.insertYaHighInterview(yaHighInterview));
    }

    /**
     * 修改高频面试题
     */
    @RequiresPermissions("teaching:interview:edit")
    @Log(title = "高频面试题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YaHighInterview yaHighInterview)
    {
        return toAjax(yaHighInterviewService.updateYaHighInterview(yaHighInterview));
    }

    /**
     * 删除高频面试题
     */
    @RequiresPermissions("teaching:interview:remove")
    @Log(title = "高频面试题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yaHighInterviewService.deleteYaHighInterviewByIds(ids));
    }
}
